<?php
// +----------------------------------------------------------------------
// | ManniuRead
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2016 http://manniuyun.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: heitao <read@manniuyun.com>
// +----------------------------------------------------------------------

namespace app\book\base;

use manniu\controller\MemberBase;

class BookMemberBase extends MemberBase{
	/**
     * TP初始化方法
     * @access public
     */
    public function _initialize(){
    	parent::_initialize();

        // 登录前允许访问的地址
        $this->login_allow = [
            url('book/member.Login/index'),
            url('book/member.Login/ajaxLogin'),
            url('book/member.Login/thirdLogin'),
            url('book/member.Login/callback'),
            url('book/member.Register/index')
        ];
    	// 登录后拒绝访问的地址
        $this->logged_deny = [
            url('book/member.Login/index'),
            url('book/member.Login/ajaxLogin'),
            url('book/member.Login/thirdLogin'),
            url('book/member.Register/index')
        ];

        // 检查会员是否登录
        if($this->checkLogin()){
            if(in_array($this->currentActionUrl, $this->logged_deny)){
                $this->redirect('book/member.Index/index');
            }
        }else{
            if(!in_array($this->currentActionUrl, $this->login_allow)){
                if($this->request->isAjax()){
                    $this->error('抱歉，请登录后再执行相关操作！');
                }else{
                    $this->redirect('book/member.Login/index');
                }
            }
        }
    }
}
